<!--
This script displays the SunSpots' most recent data
-->


<?php

// connect and select the database
// use require once here so that if some silly person tries to connect to it
// redundantly, it ignores the second call.
require_once ("../mysql/mysql_connect.php");

// The old way of getting current data (displays a different data table for each sensor):
$resultSet = mysql_query("CALL RoomNanny.getLatestData()");

/*
// Now we want to display data for the currently active sensor.

// To do this, we get all the active sensors:
$sensors = mysql_query("CALL RoomNannyDebug.getActiveSensors()");

// Then, get the currently active sensor (for now we'll just default to the first sensor)
$active_sensor = mysql_fetch_array($sensors);

if(!$currentID)
{
    $currentID = 2;
}

// Get the active sensor's most recent data
$resultSet = mysql_query("CALL RoomNannyDebug.getLatestDataOfSensor($currentID)");
*/

// Finally, display each row from result set (should only be 1)
while($row = mysql_fetch_row($resultSet))
{

    // Print out our table with the latest data
    echo "<h2>Current View:</h2>
    
    <table id='data'>

        <!--Sensor ID-->
        <tr>
            <td>
            Sensor number:<br/>
            </td>
            <td>
                $row[1]
            </td>
        </tr>

	<!--Date-->
        <tr>
            <td>
            Date:<br/>
            </td>
            <td>
                $row[2]
            </td>
        </tr>

        <!--Time-->
        <tr>
            <td>
            Time:<br/>
            <td>
                $row[3]
            </td>
        </tr>
 
        <!--Temperature-->
        <tr>
          <td>
          Temperature is:
          </td>
          <td>
          $row[4]&deg F
          </td>
        </tr>

        <!--Light on (1 if true, 0 if false)-->
        <tr>
          <td>
          Light on:
          </td>
          <td>
          $row[5]
          </td>
        </tr>

        <!--Door moved in the last time interval (1 if true, 0 if false)-->
        <tr>
          <td>
          Door Moved:
          </td>
          <td>
          $row[6]
          </td>
        </tr>
    </table>"; //end echo
}

?>
